/*******************************************************************************
*
*   FILE NAME:
*       RenderTarget2D.cpp - RenderTarget2D class implementation
*
*   DESCRIPTION:
*       Contains a 2D texture that can be used as a render target.
*
*******************************************************************************/
#include "RenderTarget2D.h"

RenderTarget2D::RenderTarget2D( GraphicsDevice& graphics_device, uint32 width, uint32 height )
    : mRenderTargetView( NULL ),
      mTexture( NULL )
{
    D3D11_TEXTURE2D_DESC td;
    ZeroMemory( &td, sizeof( D3D11_TEXTURE2D_DESC ) );
    td.Width = width;
	td.Height = height;
	td.MipLevels = 1;
	td.ArraySize = 1;
	td.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	td.SampleDesc.Count = 1;
	td.Usage = D3D11_USAGE_DEFAULT;
	td.BindFlags = D3D11_BIND_RENDER_TARGET;
	td.CPUAccessFlags = 0;
	td.MiscFlags = 0;
    graphics_device.mDevice->CreateTexture2D( &td, NULL, &mTexture );

    D3D11_RENDER_TARGET_VIEW_DESC rtvd;
    rtvd.Format = td.Format;
	rtvd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
	rtvd.Texture2D.MipSlice = 0;
    graphics_device.mDevice->CreateRenderTargetView( mTexture, &rtvd, &mRenderTargetView );
}

RenderTarget2D::~RenderTarget2D( void )
{
    if( mRenderTargetView != NULL )
    {
        mRenderTargetView->Release();
    }
    if( mTexture != NULL )
    {
        mTexture->Release();
    }
}